package com.like.entity;

import android.text.TextUtils;

import org.greenrobot.eventbus.EventBus;

public class EventWrapper {

	public Object data;
	public Object[] attaches;
	public String targetClassName;
	public int requestCode;
	public String tag;

	public EventWrapper(Object data, Class<?> targetClass, int requestCode) {
		this.data = data;
		this.targetClassName = targetClass.getName();
		this.requestCode = requestCode;
	}

	public EventWrapper(Object data, Class<?> targetClass, int requestCode,
			Object... attaches) {
		this.data = data;
		this.targetClassName = targetClass.getName();
		this.requestCode = requestCode;
		this.attaches = attaches;
	}

	public EventWrapper(Object data, String tag) {
		this.data = data;
		this.tag = tag;
	}

	public static boolean isMatch(EventWrapper event, Class<?> clazz,
			int requestCode, boolean block) {
		String thisClassName = clazz.getName();
		boolean isMatch = TextUtils
				.equals(event.targetClassName, thisClassName)
				&& event.requestCode == requestCode;
		if (isMatch && block)
			EventBus.getDefault().removeStickyEvent(event);
		return isMatch;
	}

	public static boolean isMatch(EventWrapper event, Class<?> clazz,
			int requestCode) {
		String thisClassName = clazz.getName();
		boolean isMatch = TextUtils
				.equals(event.targetClassName, thisClassName)
				&& event.requestCode == requestCode;
		if (isMatch)
			EventBus.getDefault().removeStickyEvent(event);
		return isMatch;
	}

	public static boolean isMatch(EventWrapper event, String tag) {
		boolean isMatch = TextUtils.equals(event.tag, tag);
		if (isMatch)
			EventBus.getDefault().removeStickyEvent(event);
		return isMatch;
	}

	public static boolean isMatch(EventWrapper event, String tag, boolean block) {
		boolean isMatch = TextUtils.equals(event.tag, tag);
		if (isMatch && block)
			EventBus.getDefault().removeStickyEvent(event);
		return isMatch;
	}

}
